package com.wanlian.router.ui.me.message;

import android.support.annotation.Nullable;
import android.view.View;

import com.smart.android.ui.BaseActivity;
import com.smart.android.ui.app.IntentExtra;
import com.wanlian.router.R;
import com.wanlian.router.net.NetWorkingClient;
import com.wanlian.router.net.ResponseData;
import com.wanlian.router.net.internal.INetCallBack;

/**
 * Created by Hyu on 2018/8/31.
 * Email: fvaryu@qq.com
 */
public class MessageCenterActivity extends BaseActivity {

    MessageFragment mMessageFragment;

    @Override
    protected int layout() {
        return R.layout.activity_fragment;
    }

    @Override
    public void initUI() {
        super.initUI();
        setTitle("我的消息");
        setNextClickLisener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                NetWorkingClient.getInstance().updateMessageAllRead(getActivity(), new INetCallBack() {
                    @Override
                    public void onFinish(ResponseData response, @Nullable Object o) {
                        if (response.isSuccess()) {
                            setNextEnable(false);
                            setNextColor(R.color.color_99);
                            mMessageFragment.loadData(true);
                        } else {
                            showToast(response.getMessage());
                        }
                    }
                });
            }
        });

        setNextText("全部标为已读");
        if (getIntent().getBooleanExtra(IntentExtra.EXTRA_BOOL, false)) {
            setNextColor(R.color.color_blue);
            setNextEnable(true);
        } else {
            setNextEnable(false);
            setNextColor(R.color.color_99);
        }


    }

    @Override
    public void initData() {
        super.initData();

        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment, mMessageFragment = MessageFragment.newInstance(), "message")
                .commit();
    }
}
